/*
 * @Author       : Hejh(3010733382@qq.com)
 * @Version      : V1.0
 * @Date         : 2024-01-29 12:45:52
 * @Description  : 文件资源相关接口
 */

import type { LogPageRes } from '@/types/log'
import type { RoleRes } from '@/types/role'
import type {
  CreateDirReq,
  RenameDirReq,
  MoveSourceReq,
  DelSourceReq,
  SourcePageRes,
  SourceReq,
  CreateFileReq,
  FileTypeSourceReq,
  BinSourceReq,
  BinSourcePageReq,
  SourceRes,
  SourceAuthReq,
  SourceLogReq,
  LinkSourceReq
} from '@/types/source'
import request from '@/utils/request'

// 分页查询文件资源接口
export const getSourceByPage = (params: SourceReq) => {
  return request.get<SourcePageRes>('/source/list', { params })
}

// 分页查询外链分享的文件资源接口
export const getLinkSourceByPage = (params: LinkSourceReq) => {
  return request.get<SourcePageRes>('source/linkShare/list', { params })
}

// 根据sourceId查询文件资源接口
export const getSourceById = (params: { sourceId: string }) => {
  return request.get<SourceRes>('/source/id/list', { params })
}

// 根据sourceId查询文件日志接口
export const getSourceLogById = (params: SourceLogReq) => {
  return request.get<LogPageRes>('/source/log/id', { params })
}

// 分页根据文件类型查询文件资源接口
export const getFileTypeSourceByPage = (params: FileTypeSourceReq) => {
  return request.get<SourcePageRes>('/source/fileType/list', { params })
}

// 分页查询回收站的接口文件
export const getBinSourceByPage = (params: BinSourcePageReq) => {
  return request.get<SourcePageRes>('/source/bin/list', { params })
}

// 创建文件夹
export const createSourceDir = (data: CreateDirReq) => {
  return request.post('/source/createDir', data)
}

// 创建文件接口
export const createFile = (data: CreateFileReq) => {
  return request.post('/source/createFile', data)
}

// 文件重命名
export const renameSource = (data: RenameDirReq) => {
  return request.put('/source/rename', data)
}

// 文件移动
export const moveSource = (data: MoveSourceReq) => {
  return request.put('/source/move', data)
}

// 文件复制
export const copySource = (data: MoveSourceReq) => {
  return request.put('/source/copy', data)
}

// 文件资源放入回收站接口
export const binSource = (data: BinSourceReq) => {
  return request.delete('/source/bin', { data })
}

// 还原回收站接口
export const recSource = (data: DelSourceReq) => {
  return request.delete('/source/recycle', { data })
}

// 文件资源彻底删除，清空回收站接口
export const delSource = (data: DelSourceReq) => {
  return request.delete('/source/delete', { data })
}

// 单文件下载接口
export const fileDownload = (data: { sourceId: string }) => {
  return request.post<any>('/source/fileDownload', data, {
    responseType: 'arraybuffer'
  })
}

// 文件打包下载接口
export const zipDownload = (data: { sourceIds: string[] }) => {
  return request.post<any>('/source/zipDownload', data, {
    responseType: 'arraybuffer'
  })
}

// 文件授权接口
export const authSource = (data: SourceAuthReq) => {
  return request.post('/source/auth', data)
}

// 获取当前用户对文件列表的文档权限数组
export const getSourceAuth = (data: { sourceIds: string[] }) => {
  return request.post<string[]>('/source/sourceAuth', data)
}

// 获取当前用户对文件的文档角色
export const getSourceRole = (data: { sourceId: string }) => {
  return request.post<RoleRes>('/source/sourceRole', data)
}
